<template>
  <a-card :bordered="false">
    <s-table
      ref="table"
      size="default"
      rowKey="id"
      :columns="columns"
      :data="loadData"
      :alert="options.alert"
      :rowSelection="options.rowSelection"
    >
      <span slot="serial" slot-scope="text, record, index">
        {{ index + 1 }}
      </span>
      <span slot="type" slot-scope="text">
        {{ statisticsMap[text].value }}
      </span>
    </s-table>
    <farming-list ref="farmingDialog"></farming-list>
  </a-card>
</template>

<script>
import { STable, Ellipsis } from '@/components'
import { getStatisticsList } from '@/api/system/system'
export default {
  name: 'DataStatis',
  components: {
    STable,
    Ellipsis
  },
  data () {
    return {
      statisticsMap: {
        FARMING_INSPECTION: {
          value: '养殖巡塘探针'
        },
        INSPECTION: {
          value: '底部巡塘指针'
        },
        WATER_QUALITY: {
          value: '水质监测探针'
        }
      },
      mdl: {},
      // 查询参数
      queryParam: {},
      // 表头
      columns: [
        {
          title: '序号',
          scopedSlots: { customRender: 'serial' }
        },
        {
          title: '统计名',
          dataIndex: 'type',
          scopedSlots: { customRender: 'type' }
        },
        {
          title: '计数',
          dataIndex: 'percentRate'
        }
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        console.log('loadData.parameter', parameter)
        return getStatisticsList(Object.assign(parameter))
          .then(res => {
            console.log('res', res)
            return res
          })
      },
      selectedRowKeys: [],
      selectedRows: [],
      // custom table alert & rowSelection
      options: {
        alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
        rowSelection: {
          selectedRowKeys: this.selectedRowKeys,
          onChange: this.onSelectChange
        }
      }
    }
  },
  created () {
    this.tableOption()
  },
  methods: {
    tableOption () {
      this.options = {
        alert: false,
        rowSelection: null
      }
      this.optionAlertShow = false
    }
  }
}
</script>
